# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer:
pkgname=mingw-w64-gcc-base
pkgver=8.3.0
pkgrel=2
_islver=0.20
pkgdesc="Cross GCC for the MinGW-w64 cross-compiler (bootstrap)"
url="http://gcc.gnu.org"
arch="x86_64 x86"
license="GPL-3.0-or-later"
depends="mingw-w64-binutils mingw-w64-headers mingw-w64-headers-bootstrap !mingw-w64-gcc"
makedepends="zlib-dev mpc1-dev gmp-dev mpfr-dev"
source="
	$pkgname-$pkgver.tar.xz::https://ftp.gnu.org/gnu/gcc/gcc-$pkgver/gcc-$pkgver.tar.xz
	isl-${_islver}.tar.bz2::http://isl.gforge.inria.fr/isl-${_islver}.tar.bz2
	"
builddir="$srcdir/gcc-$pkgver"

case "$CARCH" in
	x86_64) _target="x86_64-w64-mingw32" ;;
	x86) _target="i686-w64-mingw32" ;;
esac

# Directory for our out-of-tree builds
_gccdir="$srcdir"/gcc-build-${_target}

prepare() {
	default_prepare

	# Do not install libiberty
	sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in
	sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" gcc/configure

	# link isl for in-tree builds
	ln -sf ../isl-${_islver} isl

	mkdir -p "$_gccdir"
}

build() {
	cd "$_gccdir"
	"$builddir"/configure \
		--prefix=/usr \
		--target=${_target} \
		--enable-languages=c,lto \
		--enable-static \
		--with-system-zlib \
		--enable-lto --disable-dw2-exceptions \
		--disable-ns --enable-version-specific-runtime-libs \
		--disable-multilib --enable-checking=release
	make all-gcc
}

package() {
	cd "$_gccdir"
	make DESTDIR="$pkgdir" install-gcc

	strip "${pkgdir}"/usr/bin/${_target}-*
	strip "${pkgdir}"/usr/libexec/gcc/${_target}/${pkgver}/lto*
	strip "${pkgdir}"/usr/libexec/gcc/${_target}/${pkgver}/cc1
	strip "${pkgdir}"/usr/libexec/gcc/${_target}/${pkgver}/collect2

	rm -rf "${pkgdir}"/usr/share/man
	rm -rf "${pkgdir}"/usr/share/info
	rm -rf "${pkgdir}"/usr/share/locale
}

sha512sums="1811337ae3add9680cec64968a2509d085b6dc5b6783fc1e8c295e3e47416196fd1a3ad8dfe7e10be2276b4f62c357659ce2902f239f60a8648548231b4b5802  mingw-w64-gcc-base-8.3.0.tar.xz
afe2e159b74646a26449268637403d271f9e3f6410d8cc1c9cffca41370c4357b165dea844db0c2a654591f954e54710dda650c8088abd4711406aa6302da950  isl-0.20.tar.bz2"
